package com.grgbanking.it.system.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.grgbanking.it.common.json.JSONHelper;
import com.grgbanking.it.system.service.IDepartmentService;

/**
 * 部门Controller
 * 
 * DepartmentController
 * 
 * @author 潘广伟
 * @Email p_3er@qq.com
 * @Date 2014-12-15 下午2:45:35
 * 
 * @version 1.0.0
 *
 */
@Controller
@RequestMapping("/system")
public class DepartmentController {
	
	@Autowired
	private IDepartmentService departmentService;

	/**
	 * 加载部门树
	 * 
	 * @param parentId
	 * @return
	 */
	@ResponseBody  
	@RequestMapping("department/tree")
	public Object loadGrgemEquipments(Integer parentId,boolean isReflesh){  
		String json = null;
		try {
			System.out.println(isReflesh);
			json = departmentService.getDepartmentTree(parentId,isReflesh);
		} catch (Exception e) {
			e.printStackTrace();
		} 
		
		System.out.println(json);
		return json;  
	}   
	
	/**
	 * 同步部门及用户到微信
	 * synchOriginzation
	 * 
	 * @param name
	 * @param departmentId
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	@ResponseBody  
	@RequestMapping("department/synchOriginzation")
    public Object synchOriginzation(Integer deptId){ 
		String json = null;
        try {
        	departmentService.updateOrganizationToWX(deptId);
        	json = JSONHelper.getSuccessMessage("操作成功");
        } catch (Exception e) {
			e.printStackTrace();
			json = JSONHelper.getExceptionMessage(e);
		}  
        return json;  
    }   

}
